import { useTable, LIST_TYPE } from '@crud/index';
import { getLecList } from '@/api/crm-agency/dyj/lecturer';

// 查询

// 表格
export const useTableList = (options: any = {}) => {
  // TODO:
  const columns: any = [
    { label: '排名', prop: 'rank', width: 80, fixed: 'left' },
    { label: '讲师名称', prop: 'name', minWidth: 120 },
    { label: '讲师手机号', prop: 'mobile', minWidth: 120 },
    { label: '兑换总数', prop: 'code_cnt', minWidth: 120, render: 'code_cnt' },
    { label: '绑定总数', prop: 'bind_cnt', minWidth: 120, render: 'bind_cnt' },
    { label: '佣金总数', prop: 'cos_fee', minWidth: 120, render: 'cos_fee' },
    { label: '剩余兑换码', prop: 'surplus_exchange_code_count', minWidth: 120, render: 'surplus_exchange_code_count' },
    { label: '剩余渠道码', prop: 'surplus_channel_code_count', minWidth: 120, render: 'surplus_channel_code_count' },
    { label: '转化率', prop: 'cvr', minWidth: 120, type: 'percent' },
    { label: '昨日绑定数', prop: 'y_bind_cnt', minWidth: 120, render: 'y_bind_cnt' },
    { label: '近7日绑定数', prop: 'day7_bind_cnt', minWidth: 120, render: 'day7_bind_cnt' },
    { label: '跟进人', prop: 'follower', minWidth: 120, render: (s: any) => s.row.follower || '--' },
    { label: '操作', align: 'center', prop: 'actions', width: 120, render: 'actions', fixed: 'right' }
  ];
  const timeChange = (values:any[]) => {
    let from = undefined;
    let to = undefined;
    if (values && values.length > 0) {
      from = values[0];
      to = values[1];
    }
    return { from, to };
  };
  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: undefined,
      // follower: '',
      from_dt: undefined,
      to_dt: undefined,
      extend_type: 2,
      _dateRange: []
    },
    columns: columns,
    getParams: (params: Record<string, any>) => {
      const { _dateRange } = params;
      const { from, to } = timeChange(_dateRange);
      return {
        ...params,
        from_dt: from,
        to_dt: to,
        _dateRange: undefined
      };
    },
    getList: getLecList
  });
};
